// Win Window
// (c) jimon game studio

#ifndef JEH_CWINDOW_WIN
#define JEH_CWINDOW_WIN

#include "IWindow.h"

#ifdef JE_DEVICE_WIN

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

namespace je
{
	namespace device
	{
		//! Win32 Window
		class CWindow_Win:public je::device::IWindow
		{
		private:
			static u32 WindowClassID;

			HWND WindowHandle;
			HDC DeviceContext;
			HINSTANCE appInstance;

			DEVMODE DefaultMode;

			jeStringd WindowClassName;

			u1 FullScreenMode;
			u1 WindowActived;
			u1 MainWindow;

			u1 NeedClose;

			jeVector2di Size;
			jeVector2di Position;
			s32 CurrentDepth;
			s32 CurrentHertz;
			s32 CurrentMSAA;

			input::IMouseDriver * MouseDriver;
			input::IKeyDriver * KeyDriver;

			jeVector2di GetWindowGlobalSize(u1 Fullscreen,const jeVector2di & RecalcSize)
			{
				RECT WindowRect;
				WindowRect.left = 0;
				WindowRect.right = (long)RecalcSize.X;
				WindowRect.top = (long)0;
				WindowRect.bottom = (long)RecalcSize.Y;

				DWORD dwExStyle;
				DWORD dwStyle;

				if (Fullscreen)
				{
					dwExStyle = WS_EX_APPWINDOW;
					dwStyle = WS_POPUP;
				}
				else
				{
					dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
					dwStyle = WS_OVERLAPPEDWINDOW;
				}

				AdjustWindowRectEx(&WindowRect,dwStyle,false,dwExStyle);

				return jeVector2di(WindowRect.right - WindowRect.left,WindowRect.bottom - WindowRect.top);
			}
		public:
			//! Constructor
			CWindow_Win(const jeVector2di & size,const jeStringd & Title,u1 fullscreen,s32 depth,s32 hertz,s32 msaa,s32 IconId,LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam));

			//! Destructor
			~CWindow_Win();

			//! Get Win32 Window Handle
			HWND GetWin32WindowHandle();

			//! Get Win32 Device Context
			HDC GetWin32DeviceContext();

			//! Set Window Active
			void SetActive(u1 Active);

			//! Set Close Flag
			void SetCloseFlag(u1 Close);

			//! Resize Window
			void Resize(const jeVector2di & NewSize);

			//! Set Size
			void SetSize(const jeVector2di & NewSize);

			//! Get Size
			const jeVector2di & GetSize();

			//! Set Window Position
			void SetPosition(const jeVector2di & NewPosition);

			//! Get Window Position
			const jeVector2di & GetPosition();

			//! Set Fullscreen Mode
			void SetFullScreen(u1 FullScreenn,const jeVector2di & NewSize,s32 Depth = 0,s32 Hertz = 0);

			//! Return true if fullscreen
			u1 IsFullScreen();

			//! Get Depth
			s32 GetDepth();

			//! Get Hertz
			s32 GetHertz();

			//! Get MSAA
			s32 GetMSAA();

			//! Set Window Title
			void SetTitle(const jeStringd & Title);

			//! Get Window Title
			jeStringd GetTitle();

			//! Set Main Window flag
			void SetMainWindow(u1 Main);

			//! Return Main Window flag
			u1 IsMainWindow();

			//! Return true if someone try to close window
			u1 IsNeedToClose();

			//! Return true if window active
			u1 IsActive();

			//! Set Focus on window
			void SetWindowFocus();

			//! Get Mouse Driver
			input::IMouseDriver * GetMouseDriver();

			//! Get Key Driver
			input::IKeyDriver * GetKeyDriver();

			//! Get Window Api Pointer
			void * GetWindowApiPointer(WindowApiPointerType Type);
		};
	}
}

#endif

#endif
